<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/19
 * Time: 15:45
 */

namespace app\admin\controller;

use app\common\model\BasicArea;

class Area extends Admin
{
    /**
     * 获取地区列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function areaList(){
        $areaModel = new BasicArea();
        $allarea = $areaModel->with(['city'=>function($qurey){
            $qurey->with('district');
        }])->where('parentid',0)->select();
        return json_msg('成功', true, $allarea);
    }

    public function getAreaList($name){
        $info = BasicArea::where('name', $name)->find();
        if($info){
            $list = BasicArea::where('parent_id', $info['parent_id'])->select();
            return $list;
        }
        return [];
    }

    public function getList(){
        $areaModel = new BasicArea();
        $allarea = $areaModel->with(['city'=>function($qurey){
            $qurey->with('district');
        }])->where('parent_id',0)->select();
//        return json_msg('成功', true, $allarea);
        json_return_code($allarea);
    }
}